home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / 1989 / 03 / fitler.lst < prev    next >
File List  |  1989-02-10  |  5KB  |  174 lines

  1. _WRITING PORTABLE APPLICATIONS WITH X/GEM_
  2. by Bill Fitler
  3.  
  4. [LISTING ONE]
  5.  
  6.           /* GEM uses 16 bit quantities for raster
  7.              coordinates */
  8.       typedef short int WORD;
  9.       WORD pxl_width, pxl_height;
  10.       WORD work_in[11], ws_handle, work_out[57];
  11.       ...
  12.           /* Open the workstation after filling in initial
  13.              defaults into work_in[] */
  14.       if( v_opnwk(work_in,&ws_handle,work_out) == FAILURE )
  15.       {   /* Handle fatal error */ }
  16.           /* After successful open, ws_handle identifies the
  17.              desired workstation and work_out contains 57
  18.              units of information about the device,
  19.              including the width and height of each pixel in
  20.              microns */
  21.       pxl_width = work_out[3];
  22.       pxl_height = work_out[4];
  23.       ...
  24.           /* Returns a value in y units that is scaled to x
  25.              units */
  26.       WORD scale_y(WORD raw_y)
  27.       {
  28.           return raw_y * pxl_width / pxl_height;
  29.       }
  30.       ...
  31.           /* Draw a square on the screen that is "x_units"
  32.              wide and looks square */
  33.       VOID draw_square(WORD x, WORD y, WORD x_units)
  34.       {
  35.           WORD xy[10];
  36.           xy[0] = x; xy[1] = y;
  37.           xy[2] = x+x_units; xy[3] = y;
  38.           xy[4] = x+x_units; xy[5] = y+scale_y(x_units);
  39.           xy[6] = x; xy[7] = y+scale_y(x_units);
  40.           xy[8] = x; xy[9] = y;
  41.           v_pline(ws_handle,5,xy);
  42.       }
  43.  
  44. [LISTING TWO]
  45.  
  46. SAMPLE SOURCE OUTPUT FROM RESOURCE CONSTRUCTION SET
  47.  
  48.  
  49.      #define T0OBJ 0
  50.      #define FREEBB 1
  51.      #define FREEIMG 1
  52.      #define FREESTR 4
  53.  
  54.      BYTE *rs_strings[] = {
  55.      "This is a Sample Dialog",
  56.      "with an image and two buttons.",
  57.      "OK",
  58.      "Cancel"};
  59.  
  60.      WORD IMAG0[] = {
  61.      0x7FF, 0xFFFF, 0xFF80, 0xC00,
  62.      0x0, 0xC0, 0x183F, 0xF03F,
  63.      0xF060, 0x187F, 0xF860, 0x1860,
  64.      0x187F, 0xF860, 0x1860, 0x187F,
  65.      0xF860, 0x1860, 0x187F, 0xF860,
  66.      0x1860, 0x187F, 0xF860, 0x1860,
  67.      0x187F, 0xF860, 0x1860, 0x187F,
  68.      0xF860, 0x1860, 0x187F, 0xF860,
  69.      0x1860, 0x187F, 0xF860, 0x1860,
  70.      0x187F, 0xF860, 0x1860, 0x187F,
  71.      0xF860, 0x1860, 0x183F, 0xF03F,
  72.      0xF060, 0xC00, 0x0, 0xC0,
  73.      0x7FF, 0xFFFF, 0xFF80, 0x0,
  74.      0x0, 0x0, 0x3F30, 0xC787,
  75.      0x8FE0, 0xC39, 0xCCCC, 0xCC00,
  76.      0xC36, 0xCFCC, 0xF80, 0xC30,
  77.      0xCCCD, 0xCC00, 0x3F30, 0xCCC7,
  78.      0xCFE0, 0x0, 0x0, 0x0};
  79.  
  80.      LONG rs_frstr[] = {
  81.      0};
  82.  
  83.      BITBLK rs_bitblk[] = {
  84.      0L, 6, 24, 0, 0, 1};
  85.  
  86.      LONG rs_frimg[] = {
  87.      0};
  88.  
  89.      ICONBLK rs_iconblk[] = {
  90.      0};
  91.  
  92.      TEDINFO rs_tedinfo[] = {
  93.      0};
  94.  
  95.      OBJECT rs_object[] = {
  96.      -1, 1, 5, G_BOX, LASTOB, SHADOWED, 0x21100L, 0,0, 43,9,
  97.      2, -1, -1, G_STRING, NONE, NORMAL, 0x0L, 10,4, 23,1,
  98.      3, -1, -1, G_STRING, NONE, NORMAL, 0x1L, 7,5, 30,1,
  99.      4, -1, -1, G_BUTTON, SELECTABLE, NORMAL, 0x2L, 10,7,
  100.              8,1,
  101.      5, -1, -1, G_BUTTON, SELECTABLE, NORMAL, 0x3L, 24,7,
  102.              8,1,
  103.      0, -1, -1, G_IMAGE, LASTOB, NORMAL, 0x0L, 19,1, 6,3};
  104.  
  105.      LONG rs_trindex[] = {
  106.      0L};
  107.  
  108.      struct foobar {
  109.           WORD dummy;
  110.           WORD *image;
  111.           } rs_imdope[] = {
  112.      0, &IMAG0[0]};
  113.  
  114.      #define NUM_STRINGS 4
  115.      #define NUM_FRSTR 0
  116.      #define NUM_IMAGES 1
  117.      #define NUM_BB 1
  118.      #define NUM_FRIMG 0
  119.      #define NUM_IB 0
  120.      #define NUM_TI 0
  121.      #define NUM_OBS 6
  122.      #define NUM_TREE 1
  123.  
  124.      BYTE pname[] = "SAMPLE.RSC";
  125.  
  126.  
  127. [LISTING THREE]
  128.  
  129. /* mevent.h - define structure for GEM evnt_event() */
  130.  
  131.      typedef struct mevent
  132.      {
  133.      UWORD   e_flags;    /* events to wait on */
  134.      UWORD   e_bclk;     /* num button clicks */
  135.      UWORD   e_bmsk;     /* which mouse buttons */
  136.      UWORD   e_bst; /* button up or down */
  137.      UWORD   e_m1flags;  /* return on entry or exit */
  138.      GRECT   e_m1;  /* rect 1 x,y,width,height */
  139.      UWORD   e_m2flags;  /* return on entry or exit */
  140.      GRECT   e_m2;  /* rect 2 x,y,width,height */
  141.      LONG    e_mepbuf;   /* message buffer pointer */
  142.      ULONG   e_time;     /* time to wait (ms) */
  143.      WORD    e_mx;  /* return x */
  144.      WORD    e_my;  /* return y */
  145.      UWORD   e_mb;  /* return which buttons */
  146.      UWORD   e_ks;  /* return kb state */
  147.      UWORD   e_kr;  /* return kb code */
  148.      UWORD   e_br;  /* return num button clicks */
  149.      CHAR    e_reserved[24];  /* for system use */
  150.      } MEVENT;
  151.  
  152.      WORD evnt_event( MEVENT * );
  153.  
  154.  
  155.  
  156. [LISTING FOUR]
  157.  
  158.      MEVENT ev_str;
  159.      ev_str.e_flags = E_KEYBD | E_TIMER;
  160.      ev_str.e_time = 10000L;  /* in milliseconds */
  161.      ret_flags = evnt_event( &ev_str );
  162.      if( ret_flags & E_KEYBD )
  163.      {
  164.           /* The user pressed a key:
  165.      Key code of key pressed returned in ev_str.e_kr;
  166.      State of shift and control keys in ev_str.e_ks */
  167.      }
  168.      if( ret_flags & E_TIMER )
  169.      {
  170.           /* 10,000 milliseconds have elapsed since the call
  171.              */
  172.      }
  173.  
  174.